﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using SHFST.UI;

namespace SHFST.Agents
{
   class InfoBox : Agent
   {
      public bool active;
      TextDisplay text;
      float textWidth;

      public void Load (SpriteFont newFont, string newText, Point newPos)
      {
         text = new TextDisplay ();
         text.Load (newFont, newPos);
         text.text = newText;
         textWidth = text.font.MeasureString (text.text).X;
      }

      public bool Update (GraphicsDevice device, int gameProgress, int speed)
      {
         if (!active && gameProgress >= text.position.X - textWidth / 2)
         {
            active = true;
            text.position.X = device.Viewport.Width;
            if (text.position.Y == 4)
            {
               text.position.Y = device.Viewport.Height * text.position.Y / 4 - sprite.frameSize.Y;
            }
            else
            {
               text.position.Y = device.Viewport.Height * text.position.Y / 4;
            }
         }
         else if (active)
         {
            if (text.position.X <= -textWidth)
            {
               return false;
            }

            text.position.X += speed;
         }

         return true;
      }

      public override void Draw (SpriteBatch batch)
      {
         text.Draw (batch);
      }
   }
}
